package es.udc.iagolast.androidJam.Util;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.util.Log;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class LinePathOverlay extends Overlay {
	private GeoPoint GeoPointInicio;
	private GeoPoint GeoPointFin;
	private Projection projection;
	private String hexColor = "#3369E8";
	private String[] colors = {"#3369E8","#D50F25","#EEB211","#009925","#666666"};
	private static int i = 0;

	

	public LinePathOverlay(GeoPoint geoPointInicio, GeoPoint geoPointFin) {
		this.GeoPointInicio = geoPointInicio;
		this.GeoPointFin = geoPointFin;
		LinePathOverlay.i++;
		Log.d("DBG","SOY EL COLOR" + colors[(LinePathOverlay.i)%4]);
		hexColor = colors[(LinePathOverlay.i)%4];
	}

	public void draw(Canvas canvas, MapView mapview, boolean shadow) {
		super.draw(canvas, mapview, shadow);

		Paint mPaint = new Paint();
		mPaint.setDither(true);
		
		mPaint.setColor(Color.parseColor(hexColor));
		

		mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
		mPaint.setStrokeJoin(Paint.Join.ROUND);
		mPaint.setStrokeCap(Paint.Cap.ROUND);
		mPaint.setStrokeWidth(6);

		Point p1 = new Point();
		Point p2 = new Point();

		projection = mapview.getProjection();
		projection.toPixels(this.GeoPointInicio, p1);
		projection.toPixels(this.GeoPointFin, p2);

		Path path = new Path();
		path.moveTo(p2.x, p2.y);
		path.lineTo(p1.x, p1.y);

		canvas.drawPath(path, mPaint);
	}

}
